using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Xml;

namespace SMTP {

public class MailSend
    {
        public void SendEmail(string emailAddress, string fromEmail, string subject, string body, List<string> attachmentList)
        {
            var email = new Email();
            try
            {
                email.strEmailTo = emailAddress;
                email.strSubject = subject;
                email.strBody = body;
                var smtpMail = new SmtpClient();
                smtpMail.Host = ConfigurationManager.AppSettings["SMTPServer"];
                smtpMail.Port = Convert.ToInt32(ConfigurationManager.AppSettings["SMTPPort"]);
                var username = ConfigurationManager.AppSettings["userName"];
                var password = ConfigurationManager.AppSettings["password"];
                var emailFrom = string.IsNullOrEmpty(fromEmail) ? ConfigurationManager.AppSettings["MailFrom"] : fromEmail;
                var networkCredential = new NetworkCredential(username, password);
                smtpMail.Credentials = networkCredential;
                var message = new MailMessage(emailFrom, emailAddress, subject, body) { IsBodyHtml = true };

                if (attachmentList != null)
                {
                    foreach (var attachment in attachmentList.Select(file => new Attachment(file)))
                    {
                        message.Attachments.Add(attachment);
                    }
                }

                smtpMail.Send(message);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}

//call here
SendEmail("hemanth@gmail.com","mailsendt@gmail.com","testMail","mail msg",new List<string> {"D:\Log\text1.txt"});
	